package com.zc.study.designPattern.结构型设计模式.flyweightPattern;

import java.util.Hashtable;

/**
 * 围棋棋子工厂类:享元工厂类,使用单例模式进行设计
 */
public class IgochessmanFactory {
    private static IgochessmanFactory instance = new IgochessmanFactory();
    private static Hashtable ht; //使用hashtable来存储享元对象,充当享元池

    private IgochessmanFactory(){
        ht = new Hashtable();
        IgoChessman black,write;
        black = new BlackIgochessman();
        ht.put("b",black);
        write = new WhiteIgochessman();
        ht.put("w",write);
    }
    //返回享元工厂类的唯一实例
    public static IgochessmanFactory getInstance(){
        return instance;
    }
    //通过key来获取存储在Hashtable中的享元对象
    public static IgoChessman getIgochessman(String color){
        return (IgoChessman)ht.get(color);
    }
}
